package com.henry.imkit.request

import com.henry.imkit.OnErrorCallback
import com.henry.imkit.network.IMExceptionHandle
import com.henry.imkit.network.RetryWithDelay
import com.henry.imkit.rx.SchedulerUtils
import io.reactivex.Observable
import io.reactivex.disposables.Disposable

fun <T> Observable<T>.ssss(
    onSuccess: (T) -> Unit,
    onError: (OnErrorCallback)? = null
): Disposable {
    return this.compose(SchedulerUtils.ioToMain())
        .retryWhen(RetryWithDelay())
        .subscribe({
            onSuccess.invoke(it)
        }, {
            IMExceptionHandle.handleException(it)
            onError?.invoke(IMExceptionHandle.errorCode, IMExceptionHandle.errorMsg)
        })
}